package org.creativor.rayson.server;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.net.InetSocketAddress;
import org.creativor.rayson.api.RpcService;
import org.creativor.rayson.api.ServiceRegistration;
import org.creativor.rayson.api.Session;
import org.creativor.rayson.common.ClientSession;
import org.creativor.rayson.demo.server.DemoServiceImpl;
import org.creativor.rayson.transport.common.Packet;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * The class <code>RpcServerTest</code> contains tests for the class
 * <code>{@link RpcServer}</code>.
 * <p>
 * Copyright Creativor Studio (c) 2011
 * 
 * @generatedBy CodePro at 11-5-7 上午2:57
 * @author Nick Zhang
 * @version $Revision: 1.0 $
 */
public class RpcServerTest
{
	/**
	 * Launch the test.
	 * 
	 * @param args
	 *            the command line arguments
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	public static void main(String[] args)
	{
		new org.junit.runner.JUnitCore().run(RpcServerTest.class);
	}
	
	/**
	 * Perform pre-test initialization.
	 * 
	 * @throws Exception
	 *             if the initialization fails for some reason
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Before
	public void setUp() throws Exception
	{
		// TODO: add additional set up code here
	}
	
	/**
	 * Perform post-test clean-up.
	 * 
	 * @throws Exception
	 *             if the clean-up fails for some reason
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@After
	public void tearDown() throws Exception
	{
		// TODO: add additional tear down code here
	}
	
	/**
	 * Run the ServiceRegistration find(RpcRequest,String) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test(expected = org.creativor.rayson.exception.ServiceNotFoundException.class)
	public void testFind_1() throws Exception
	{
		RpcServer fixture = new RpcServer();
		String serviceName = "";
		
		ServiceRegistration result = fixture.find(serviceName);
		
		// TODO: add additional test code here
		assertNotNull(result);
	}
	
	/**
	 * Run the ServiceRegistration find(RpcRequest,String) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test(expected = org.creativor.rayson.exception.ServiceNotFoundException.class)
	public void testFind_2() throws Exception
	{
		RpcServer fixture = new RpcServer();
		String serviceName = "";
		
		ServiceRegistration result = fixture.find(serviceName);
		
		// TODO: add additional test code here
		assertNotNull(result);
	}
	
	/**
	 * Run the String getServerInfo(RpcRequest) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testGetServerInfo_1() throws Exception
	{
		RpcServer fixture = new RpcServer();
		
		String result = fixture.getServerInfo();
		
		// TODO: add additional test code here
		assertEquals("Rpc server", result);
	}
	
	/**
	 * Run the void invokeCall(ServerCall) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testInvokeCall_1() throws Exception
	{
		RpcServer fixture = new RpcServer();
		ServerCall call =
				ServerCall
						.fromPacket(new InetSocketAddress(1), (byte) 1, new Packet(new byte[] {}));
		
		fixture.invokeCall(call);
		
		// TODO: add additional test code here
		// An unexpected exception was thrown in user code while executing this
		// test:
		// java.io.EOFException
		// at java.io.DataInputStream.readFully(DataInputStream.java:180)
		// at java.io.DataInputStream.readLong(DataInputStream.java:399)
		// at
		// org.creativor.rayson.server.ServerCall.fromPacket(ServerCall.java:50)
	}
	
	/**
	 * Run the void invokeCall(ServerCall) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testInvokeCall_2() throws Exception
	{
		RpcServer fixture = new RpcServer();
		ServerCall call =
				ServerCall
						.fromPacket(new InetSocketAddress(1), (byte) 1, new Packet(new byte[] {}));
		
		fixture.invokeCall(call);
		
		// TODO: add additional test code here
		// An unexpected exception was thrown in user code while executing this
		// test:
		// java.io.EOFException
		// at java.io.DataInputStream.readFully(DataInputStream.java:180)
		// at java.io.DataInputStream.readLong(DataInputStream.java:399)
		// at
		// org.creativor.rayson.server.ServerCall.fromPacket(ServerCall.java:50)
	}
	
	/**
	 * Run the void invokeCall(ServerCall) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testInvokeCall_3() throws Exception
	{
		RpcServer fixture = new RpcServer();
		ServerCall call =
				ServerCall
						.fromPacket(new InetSocketAddress(1), (byte) 1, new Packet(new byte[] {}));
		
		fixture.invokeCall(call);
		
		// TODO: add additional test code here
		// An unexpected exception was thrown in user code while executing this
		// test:
		// java.io.EOFException
		// at java.io.DataInputStream.readFully(DataInputStream.java:180)
		// at java.io.DataInputStream.readLong(DataInputStream.java:399)
		// at
		// org.creativor.rayson.server.ServerCall.fromPacket(ServerCall.java:50)
	}
	
	/**
	 * Run the void invokeCall(ServerCall) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testInvokeCall_4() throws Exception
	{
		RpcServer fixture = new RpcServer();
		ServerCall call =
				ServerCall
						.fromPacket(new InetSocketAddress(1), (byte) 1, new Packet(new byte[] {}));
		
		fixture.invokeCall(call);
		
		// TODO: add additional test code here
		// An unexpected exception was thrown in user code while executing this
		// test:
		// java.io.EOFException
		// at java.io.DataInputStream.readFully(DataInputStream.java:180)
		// at java.io.DataInputStream.readLong(DataInputStream.java:399)
		// at
		// org.creativor.rayson.server.ServerCall.fromPacket(ServerCall.java:50)
	}
	
	/**
	 * Run the void invokeCall(ServerCall) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testInvokeCall_5() throws Exception
	{
		RpcServer fixture = new RpcServer();
		ServerCall call =
				ServerCall
						.fromPacket(new InetSocketAddress(1), (byte) 1, new Packet(new byte[] {}));
		
		fixture.invokeCall(call);
		
		// TODO: add additional test code here
		// An unexpected exception was thrown in user code while executing this
		// test:
		// java.io.EOFException
		// at java.io.DataInputStream.readFully(DataInputStream.java:180)
		// at java.io.DataInputStream.readLong(DataInputStream.java:399)
		// at
		// org.creativor.rayson.server.ServerCall.fromPacket(ServerCall.java:50)
	}
	
	/**
	 * Run the boolean isSupportedVersion(Session) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testIsSupportedVersion_1() throws Exception
	{
		RpcServer fixture = new RpcServer();
		Session session = new ClientSession();
		
		boolean result = fixture.isSupportedVersion(session);
		
		// TODO: add additional test code here
		assertEquals(true, result);
	}
	
	/**
	 * Run the ServiceRegistration[] list(RpcRequest) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testList_1() throws Exception
	{
		RpcServer fixture = new RpcServer();
		
		ServiceRegistration[] result = fixture.list();
		
		// TODO: add additional test code here
		assertNotNull(result);
		assertEquals(0, result.length);
	}
	
	/**
	 * Run the ServiceRegistration[] list(RpcRequest) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testList_2() throws Exception
	{
		RpcServer fixture = new RpcServer();
		
		ServiceRegistration[] result = fixture.list();
		
		// TODO: add additional test code here
		assertNotNull(result);
		assertEquals(0, result.length);
	}
	
	/**
	 * Run the void registerService(String,String,RpcService) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testRegisterService_1() throws Exception
	{
		RpcServer fixture = new RpcServer();
		String serviceName = "";
		String description = "";
		RpcService serviceInstance = new DemoServiceImpl();
		
		fixture.registerService(serviceName, description, serviceInstance);
		
		// TODO: add additional test code here
	}
	
	/**
	 * Run the void registerService(String,String,RpcService) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testRegisterService_2() throws Exception
	{
		RpcServer fixture = new RpcServer();
		String serviceName = "";
		String description = "";
		RpcService serviceInstance = new DemoServiceImpl();
		
		fixture.registerService(serviceName, description, serviceInstance);
		
		// TODO: add additional test code here
	}
	
	/**
	 * Run the void registerService(String,String,RpcService) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testRegisterService_3() throws Exception
	{
		RpcServer fixture = new RpcServer();
		String serviceName = "";
		String description = "";
		RpcService serviceInstance = new DemoServiceImpl();
		
		fixture.registerService(serviceName, description, serviceInstance);
		
		// TODO: add additional test code here
	}
	
	/**
	 * Run the RpcServer() constructor test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testRpcServer_1() throws Exception
	{
		
		RpcServer result = new RpcServer();
		
		// TODO: add additional test code here
		assertNotNull(result);
		assertEquals("{version: 1, port: 6660}", result.toString());
		assertEquals(1, result.getVersion());
		assertEquals(6660, result.getPortNumber());
	}
	
	/**
	 * Run the RpcServer(int) constructor test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testRpcServer_2() throws Exception
	{
		int portNumber = 1;
		
		RpcServer result = new RpcServer(portNumber);
		
		// TODO: add additional test code here
		assertNotNull(result);
		assertEquals("{version: 1, port: 1}", result.toString());
		assertEquals(1, result.getVersion());
		assertEquals(1, result.getPortNumber());
	}
	
	/**
	 * Run the void start() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testStart_1() throws Exception
	{
		RpcServer fixture = new RpcServer();
		
		fixture.start();
		
		// TODO: add additional test code here
	}
	
	/**
	 * Run the void start() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test(expected = java.net.BindException.class)
	public void testStart_2() throws Exception
	{
		RpcServer fixture = new RpcServer();
		
		fixture.start();
		
		// TODO: add additional test code here
	}
	
	/**
	 * Run the void start() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test(expected = java.net.BindException.class)
	public void testStart_3() throws Exception
	{
		RpcServer fixture = new RpcServer();
		
		fixture.start();
		
		// TODO: add additional test code here
	}
	
	/**
	 * Run the void stop() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午2:57
	 */
	@Test
	public void testStop_1() throws Exception
	{
		RpcServer fixture = new RpcServer();
		
		fixture.stop();
		
		// TODO: add additional test code here
	}
}
